package com.woniu.controller;

import com.woniu.entity.Documents;
import com.woniu.service.DocumentsService;
import com.woniu.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author nanqiao
 * @description 文件上传
 * @createDate 2025-06-09 17:11:49
 * @Entity com.woniu.entity.CtfContainer
 */
@RestController
@RequestMapping("/documents")
public class DocumentsController {
    @Autowired
    private DocumentsService documentsService;

    /**
     * @Author zhaoj
     * @Date 2025/6/10 13:13
     * @Description TODO
     * @Params 
     * @Return 
     **/
    @PostMapping("/addDocuments")
    public ResponseData<Documents> addDocuments(@RequestParam("file") MultipartFile file) {
        try {
            Documents documents = documentsService.addDocuments(file);
            return ResponseData.ok(documents);  // 使用 ResponseData 封装返回数据
        } catch (Exception e) {
            return ResponseData.fail(500, "文件上传失败: " + e.getMessage());  // 处理异常情况
        }
    }
}
